package com.netsdk.lht2.push;

import cn.hutool.core.util.StrUtil;
import com.netsdk.demo.util.sql.JdbcUtils;
import com.netsdk.demo.util.sql.Trajectory;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Coordinates {
    static Map<String,List<Coordinate>> data = new HashMap<>();
    static  Map<String,String> cogMap = new HashMap<>();
    static {
        try {
            init();
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
    }


    private static  void init() throws SQLException {
        String sql3 = "select t.nLaneIndex,t.nJun,t.device_address,t.nChannel,t.nLane,t.nLaneNo,t.direction,t.cog,t.size," +
                "t.usetime,t.befor,t.total,t.zb1,t.zb2,t.zb3,t.zb4,t.zb5,t.zb6,t.zb7,t.zb8,t.zb9,t.zb10,t.zb11,t.zb12,t.alltime, t.offset  "
                + ",t.green  from zbset t where  zb1 is not null ";
        List<Map<String, Object>> zblist = JdbcUtils.queryBean(sql3);
        for (Map<String, Object> map : zblist) {
            String nLaneIndex = map.get("nLaneIndex").toString();
            String nChannel = map.get("nChannel").toString();
            List<Coordinate> list = new ArrayList<>();
            if(!StrUtil.isBlankIfStr(map.get("zb1") )){
                list.add(dealLonlat(map.get("zb1").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb2") )){
                list.add(dealLonlat(map.get("zb2").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb3") )){
                list.add(dealLonlat(map.get("zb3").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb4") )){
                list.add(dealLonlat(map.get("zb4").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb5") )){
                list.add(dealLonlat(map.get("zb5").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb6") )){
                list.add(dealLonlat(map.get("zb6").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb7") )){
                list.add(dealLonlat(map.get("zb7").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb8") )){
                list.add(dealLonlat(map.get("zb8").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb9") )){
                list.add(dealLonlat(map.get("zb9").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb10") )){
                list.add(dealLonlat(map.get("zb10").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb11") )){
                list.add(dealLonlat(map.get("zb11").toString()));
            }
            if(!StrUtil.isBlankIfStr(map.get("zb12") )){
                list.add(dealLonlat(map.get("zb12").toString()));
            }
            data.put(nChannel + "-" + nLaneIndex,list);
            cogMap.put(nChannel,map.get("cog").toString());
        }
    }
    public static  Coordinate dealLonlat(String zb){
        String[] arr = zb.split(",");
        return new Coordinate(arr[0].trim(),arr[1].trim());
    }
    public static  String getCog(String channel){
        return cogMap.get(channel);
    }
    public static  List<Coordinate> getCoordinate(String index){
        return data.get(index);
    }

    public static class Coordinate{
        private String lon;
        private String lat;

        public Coordinate(String lon, String lat) {
            this.lon = lon;
            this.lat = lat;
        }

        public String getLon() {
            return lon;
        }

        public String getLat() {
            return lat;
        }
    }
}
